Hi everyone! Welcome to this penultimate class of the Fall semester. Next week is the second set of project presentations and then it is winter holidays. The goal of today is to 1) have some fun, 2) further build some of your practical skills wrangling and visualizing data and 3) gain experience using an API.

See the slides on the course overview page for more information.

Getting set up

# Credit to danielle smith for this basis of this great little function: 
# https://gist.github.com/smithdanielle/9913897
install_check <- function(pkg){
    new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
    if (length(new.pkg)) 
        install.packages(new.pkg, dependencies = TRUE)
}

# Here is a list of the packages we will need today
packages = c("tidyverse", "polite",
             "TMDb", "keyring", "glue", "lubridate", "ggpubr")

install_check(packages)

# Load tidyverse now, we'll load the others as we need them
library(tidyverse) # Liza's fave package of packages ever
library(glue) # awesome package that we don't have time to talk about
library(lubridate) # helps make dates much easier

IMDB

library(polite) # let's us check the robotstxt, and also pass user agent information to the site, if we choose

bow("https://www.imdb.com/search/keyword/?keywords=christmas&ref_=kw_nxt&sort=moviemeter,asc&mode=detail&page=2&title_type=movie")
## <polite session> https://www.imdb.com/search/keyword/?keywords=christmas&ref_=kw_nxt&sort=moviemeter,asc&mode=detail&page=2&title_type=movie
##     User-agent: polite R package - https://github.com/dmi3kno/polite
##     robots.txt: 26 rules are defined for 1 bots
##    Crawl delay: 5 sec
##   The path is scrapable for this user-agent

Let’s looks at the robots.txt and Terms and Conditions ourselves.

browseURL("https://www.imdb.com/conditions")
browseURL("https://www.imdb.com/robots.txt")

So, can we ethically scrape IMDB?

The Movie Database (TMDb)

Let’s take a look a different online movie database…

browseURL("https://www.themoviedb.org/terms-of-use")

back to the slides!

API

We can’t scrape ethically, but we can use the API. In fact, there exists a package to helps us do this easily in R!

Libraries we need

You need the TMDb package that helps us access the API through R. We’re also going to install keyring which is a nice way to keep your private API key safe but still share all the code we’re using. `

library(TMDb) # provides access to the API
library(keyring) # for storing our API key

Set up API key, super secretly

#This will create a pop-up prompting you for a password. Put your api key in there.
key_set("TMDB_API")

The data

Let’s explore some functions!

You can find more information in the documentation on CRAN or on this more interactive site

Let’s find out what kind of genre classifications we have.

genres <- genres_movie_list(key_get("TMDB_API"))$genres
genres

We can use these ids later to help us search things.

A little error fixing for keywords

There is an error in the package for this function that is supposed to search keywords, so I’ve edited it here.

search_keyword <- function(api_key, query, page=1){
    
    if(page<1 || page>1000){
        stop("page must be a number between 1 and 1000")
    }
    
    l <- list(page=page)
    l <- l[!is.na(l)]
    
    params <- paste("&", names(l), "=",l, sep="", collapse="")
    url <- fromJSON(GET(URLencode(url<-paste("http://api.themoviedb.org/3/search/keyword?api_key=", 
                                             api_key, "&query=", query, params, sep="")))$url)
    
    return(url)
    
}

Opportunity: Put in a pull request on the GitHub for the package to fix this function! https://github.com/AndreaCapozio/TMDb

# now I want to find all the Christmas keywords I could be searching
search_keyword(key_get("TMDB_API"), query = "christmas")
## $page
## [1] 1
## 
## $results
##                 name     id
## 1    christmas party   1441
## 2   saving christmas  12200
## 3   christmas lights 172742
## 4   christmas horror 186466
## 5    christmas music 186933
## 6     christmas card 188345
## 7   christmas spirit 193048
## 8  christmas reunion 196018
## 9          christmas 207317
## 10  christmas parade 228081
## 11    anti christmas 232431
## 12   christmas magic 240515
## 13  christmas dinner 252441
## 14    christmas food 254789
## 15   white christmas 258426
## 16     christmas eve 260365
## 17   christmas movie 265857
## 18 christmas pageant 269672
## 19 christmas pudding 270896
## 20  father christmas 272288
## 
## $total_pages
## [1] 2
## 
## $total_results
## [1] 39

Notice that this only has 20 rows… are there more Christmas keywords than just that? 20 seems like a suspicious tidy number…

Our problem is that this function can just pull one ‘page’ at a time, a page has 20 entries. Reading the documentation shows us that there are a maximum of 1000 pages but I think it is actually 500 based on some testing.

Thankfully, we can find out how many pages there are by just looking at the total_pages list element. Convenient!

Now, we could do a for loop to get all the pages….but it seems like the more people program the less they like for loops. We can use the map functions from purrr to do what we want and keep our code very tidy. More info here: https://speakerdeck.com/jennybc/purrr-workshop.

# write a function that runs this for command for any given page
one_page <- function(x) search_keyword(key_get("TMDB_API"), query = "christmas", page = x)

# make a vector of the pages, from 1 to the max page for this search
pages <- 1:one_page(1)$total_pages

# now use map_dfr (map specifcally for returning data frames) instead of a for loop
christmas_keywords <- map_dfr(pages, function(x) one_page(x)$results)
christmas_keywords
# later, for searching multiple IDs I need to make them a string seperated by | for "OR" or , for "AND"
xmas_ids <- glue_collapse(christmas_keywords$id, sep="|")
xmas_ids
## 1441|12200|172742|186466|186933|188345|193048|196018|207317|228081|232431|240515|252441|254789|258426|260365|265857|269672|270896|272288|5570|170496|196450|209848|228415|230851|236216|240732|250130|255088|258805|258841|260508|262034|267190|272698|272807|272808|273274

ACTVITY: Your turn! Find a keyword or set of key words you’d be interested in searching

# write a function that runs this for command for any given page
one_page <- function(x) search_keyword(key_get("TMDB_API"), query = "<PUT SEARCH TERM HERE", page = x)

# make a vector of the pages, from 1 to the max page for this search
pages <- 1:one_page(1)$total_pages

# now use map_dfr (map specifcally for returning data frames) instead of a for loop
my_keywords <- map_dfr(pages, function(x) one_page(x)$results)
my_keywords

# later, for searching multiple IDs I need to make them a string seperated by | for "OR" or , for "AND"
keywords_ids <- glue_collapse(my_keywords$id, sep="|")
keywords_ids

# change eval=FALSE in the chunk options, so that is TRUE

Searching for movies

discover_movie() lets us do some searching based on a range of criteria. I want movies that are Romance genre, and have “christmas” related keywords.

# Reusing the code structure above. This could probably be streamlined even better with a more general function
one_page <- function(x) discover_movie(key_get("TMDB_API"), with_genres = 10749, with_keywords = xmas_ids, page = x)
pages <- 1:one_page(1)$total_pages
christmas_romance <- map_dfr(pages, function(x) one_page(x)$results) %>% 
  mutate(genre_ids = as.character(genre_ids))
  
# write_csv(christmas_romance, "christmas_romance.csv")

ACTIVITY: Set up a search of your own

Visualization time! But make it UGLY…

Great resources for colours in R: http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf

christmas_romance <- read_csv("christmas_romance.csv") %>% 
  mutate(release_date = as_date(release_date)) 
## 
## ── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
## cols(
##   id = col_double(),
##   adult = col_logical(),
##   backdrop_path = col_character(),
##   genre_ids = col_character(),
##   vote_count = col_double(),
##   original_language = col_character(),
##   original_title = col_character(),
##   poster_path = col_character(),
##   title = col_character(),
##   video = col_logical(),
##   vote_average = col_double(),
##   popularity = col_double(),
##   overview = col_character(),
##   release_date = col_date(format = "")
## )
christmas_romance %>% 
  ggplot(aes(x = release_date)) +
  geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

edit <- christmas_romance %>% 
  mutate(month = month(release_date, label = TRUE),
         year = year(release_date),
         ym = paste(year, month),
         quarter = quarter(release_date, with_year = TRUE)) %>% 
  mutate(month = fct_expand(month, month.abb))

myplot <- edit %>% 
  filter(release_date > "2010-01-01") %>%
  ggplot(aes(x = month)) +
  geom_bar() + 
  scale_x_discrete(drop=FALSE) + # this bit of magic makes sure we don't drop the missing months 
  labs(title = "Release month of Christmas movies since 2010",
        x = "Month",
        y = "Number of movies released",
        caption = "Source: https://www.themoviedb.org/") +
  theme_minimal() 

myplot

sweater_bkgd <- jpeg::readJPEG("sweater_bkgd.jpg")

edit %>% 
  filter(release_date > "2010-01-01") %>%
  ggplot(aes(x = month)) +
  ggpubr::background_image(sweater_bkgd) +
  geom_bar(fill = "darkgreen") + 
  scale_x_discrete(drop=FALSE) + # this bit of magic makes sure we don't drop the missing months 
labs(title = "Release month of Christmas movies since 2010",
        x = "Month",
        y = "Number of movies released",
        caption = "By: @Liza_Bolton; Source: https://www.themoviedb.org/") +
  theme(plot.background = element_rect(fill = "darkgreen"), text = element_text(color = "white"), axis.text= element_text(color = "white"))

ggsave("my_first_ugly_plot.png", width = 7, height = 4.5)

Background images in repo from:https://kosamari.github.io/sweaterify/ and https://depositphotos.com/110626704/stock-illustration-christmas-sweater-pattern.html

Your turn! Ugly graph challenge

Use this API (or the data I have provided) and make an extremely ugly and hard to read graph! The sky is the limit (warning: stop if you make your own eyes bleed.)

Email us your ugly creations and if we get enough we can make a class gallery.

What else could we look at?

Top voted movies?

top10 <- edit %>% 
  arrange(desc(vote_count)) %>% 
  head(n = 10) %>% 
  select(title, poster_path)
top10
url <- paste0("https://image.tmdb.org/t/p/w1280/", top10$poster_path)

knitr::include_graphics(url)

Appendix

# Here is an example of pulling a list (I got the id from the URL)
list_get(key_get("TMDB_API"), 7411)
## $created_by
## [1] "Taphive"
## 
## $description
## [1] ""
## 
## $favorite_count
## [1] 0
## 
## $id
## [1] "7411"
## 
## $items
##                           original_title                      poster_path video
## 1                           Rare Exports /jzaweEESl54ejxo3EE5uNL8lgTn.jpg FALSE
## 2                 東京ゴッドファーザーズ /ukhvxpVcBsb1MpRRwiqEIwyKdUX.jpg FALSE
## 3                      A Christmas Story /naZ22fATqn5MiYbrskkZbVeiNoM.jpg FALSE
## 4                       Arthur Christmas /brELZkSbkLrcCXJ0xt5hQUMXhut.jpg FALSE
## 5                               Die Hard /p5hURTvac8sxLRhe5hLchvfy5Pu.jpg FALSE
## 6         The Nightmare Before Christmas /e4pZZR1SZByveyWczQBmiXJ0lXP.jpg FALSE
## 7                                    Elf /zDHFQmaxlTIJGQDfTrLTL9RK2tQ.jpg FALSE
## 8                          Lethal Weapon /fTq4ThIP3pQTYR9eDepsbDHqdcs.jpg FALSE
## 9                         Trading Places /8mBuLCOcpWnmYtZc4aqtvDXslv6.jpg FALSE
## 10                              Gremlins /72Y1X9pMSjXQ7mKB6pBEoMhL0OQ.jpg FALSE
## 11                      Un conte de Noël /yGLrE150vchL1q1e1UNmPRPKwii.jpg FALSE
## 12                            Home Alone /9wSbe4CwObACCQvaUVhWQyLR5Vz.jpg FALSE
## 13                             Bad Santa /dt30keB9txHjYXuMzrqv6uJ499B.jpg FALSE
## 14                   Kiss Kiss Bang Bang /5cPk7YIEP6Uj9tV0mKZSsI9MGbF.jpg FALSE
## 15                     The Polar Express /hc2NFfInDrOiIgIy8TTjEZTvSkz.jpg FALSE
## 16        Home Alone 2: Lost in New York /uuitWHpJwxD1wruFl2nZHIb4UGN.jpg FALSE
## 17                     A Christmas Carol /goHDZUnqZJ7FN4h48Qh6MzJNExl.jpg FALSE
## 18                 It's a Wonderful Life /bSqt9rhDZx1Q7UZ86dBPKdNomp2.jpg FALSE
## 19                              Scrooged /uO0znfB2ZzTXA1IS7jkrjNbpkYK.jpg FALSE
## 20                      The Santa Clause /tBHDVtEcMl06FbCURRLGVg3TpXp.jpg FALSE
## 21                     A Christmas Carol /oi1NcVDXlFEsdpLp37BJmFbVlg9.jpg FALSE
## 22                                  Sint /pEPd4mgMwvz6aRhuWkmPUv98P1O.jpg FALSE
## 23                       Black Christmas /qqO98sdPgptFgCua3Z4uZDuPcmP.jpg FALSE
## 24                         Love Actually /7QPeVsr9rcFU9Gl90yg0gTOTpVv.jpg FALSE
## 25 National Lampoon's Christmas Vacation /64NKasFKx6aOTKRg4mv76l0IwZR.jpg FALSE
## 26                               Krampus /9OiZVRWjdVLQMMhM7w6ocZjPJ6V.jpg FALSE
##    vote_average popularity vote_count release_date             genre_ids
## 1           6.3      8.646        305   2010-12-03                    14
## 2           7.9     11.572        507   2003-12-29                16, 18
## 3           7.3     14.612        763   1983-11-18             35, 10751
## 4           6.7     22.432        891   2011-11-10     18, 16, 10751, 35
## 5           7.7     35.649       7674   1988-07-15                28, 53
## 6           7.8     44.010       6284   1993-10-09         14, 16, 10751
## 7           6.6     26.142       2574   2003-10-09         35, 10751, 14
## 8           7.2     22.683       2977   1987-03-06    12, 28, 35, 53, 80
## 9           7.2     12.483       2030   1983-06-07                    35
## 10          7.1     21.924       4375   1984-06-07            14, 27, 35
## 11          6.9      7.135         90   2008-05-16                18, 35
## 12          7.3      3.583       7200   1990-11-16             35, 10751
## 13          6.5     19.277       1411   2003-11-26            18, 35, 80
## 14          7.2     10.789       1776   2005-09-05            35, 80, 28
## 15          6.7     46.519       4195   2004-11-10 12, 16, 35, 14, 10751
## 16          6.6     63.949       6456   1992-11-19     35, 10751, 12, 80
## 17          6.8     45.332       3201   2009-11-04     16, 10751, 18, 14
## 18          8.2     21.080       2606   1946-12-20         18, 10751, 14
## 19          6.9      9.537        900   1988-11-22            35, 18, 14
## 20          6.4     49.990       1281   1994-11-11     14, 18, 35, 10751
## 21          7.0     11.814        109   1999-12-05                18, 14
## 22          5.1      5.593         91   2010-10-31                35, 27
## 23          6.9      6.921        376   1974-10-11          27, 9648, 53
## 24          7.1     20.264       4481   2003-09-07         35, 10749, 18
## 25          7.2     27.974       1408   1989-11-30                    35
## 26          6.0     23.499       1326   2015-11-26            27, 35, 14
##                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           overview
## 1  It's the eve of Christmas in northern Finland and an archaeological dig has just unearthed the real Santa Claus. But this particular Santa isn't the one you want coming to town. When all the local children begin mysteriously disappearing, young Pietari and his father Rauno, a reindeer hunter by trade, capture the mythological being and attempt to sell Santa to the misguided leader of the multinational corporation sponsoring the dig. Santa's elves, however, will stop at nothing to free their fearless leader from captivity.
## 2                                                                                                                                                                                                                       During a Christmas Eve in Tokyo, three homeless people, middle-aged alcoholic Gin, former drag queen Hana, and dependent runaway girl Miyuki, discover an abandoned newborn while looking through the garbage. With only a handful of clues to the baby's identity, the three misfits search the city to find its parents.
## 3                                                                                                                                                                                                                                                                                                                                                   The comic mishaps and adventures of a young boy named Ralph, trying to convince his parents, teachers, and Santa that a Red Ryder B.B. gun really is the perfect Christmas gift for the 1940s.
## 4                                                                                          Each Christmas, Santa and his vast army of highly trained elves produce gifts and distribute them around the world in one night. However, when one of 600 million children to receive a gift from Santa on Christmas Eve is missed, it is deemed ‘acceptable’ to all but one—Arthur. Arthur Claus is Santa’s misfit son who executes an unauthorised rookie mission to get the last present half way around the globe before dawn on Christmas morning.
## 5                                                                                                                                                                                                        NYPD cop John McClane's plan to reconcile with his estranged wife is thrown for a serious loop when, minutes after he arrives at her office, the entire building is overtaken by a group of terrorists. With little help from the LAPD, wisecracking McClane sets out to single-handedly rescue the hostages and bring the bad guys down.
## 6                                                                                                                                                                                            Tired of scaring humans every October 31 with the same old bag of tricks, Jack Skellington, the spindly king of Halloween Town, kidnaps Santa Claus and plans to deliver shrunken heads and other ghoulish gifts to children on Christmas morning. But as Christmas approaches, Jack's rag-doll girlfriend, Sally, tries to foil his misguided plans.
## 7                                                                                                                                                                                                               When young Buddy falls into Santa's gift sack on Christmas Eve, he's transported back to the North Pole and raised as a toy-making elf by Santa's helpers. But as he grows into adulthood, he can't shake the nagging feeling that he doesn't belong. Buddy vows to visit Manhattan and find his real dad, a workaholic publisher.
## 8                                                                                                                                                            Veteran buttoned-down LAPD detective Roger Murtaugh is partnered with unhinged cop Martin Riggs, who -- distraught after his wife's death -- has a death wish and takes unnecessary risks with criminals at every turn. The odd couple embark on their first homicide investigation as partners, involving a young woman known to Murtaugh with ties to a drug and prostitution ring.
## 9                                                                                                                                                                                                                                                                                                                                                                                                                     A snobbish investor and a wily street con-artist find their positions reversed as part of a bet by two callous millionaires.
## 10                                                                                                                                                                                                                                                                                                                      When Billy Peltzer is given a strange but adorable pet named Gizmo for Christmas, he inadvertently breaks the three important rules of caring for a Mogwai, and unleashes a horde of mischievous gremlins on a small town.
## 11                                                                                                                                                                                                              When their regal matriarch falls ill, the troubled Vuillard family come together for a hesitant Christmastime reunion. Among them is rebellious ne'er-do-well Henri and the uptight Elizabeth. Together under the same roof for the first time in many years, their intricate, long denied resentments and yearnings emerge again.
## 12                                                                                                                 Eight-year-old Kevin McCallister makes the most of the situation after his family unwittingly leaves him behind when they go on Christmas vacation. But when a pair of bungling burglars set their sights on Kevin's house, the plucky kid stands ready to defend his territory. By planting booby traps galore, adorably mischievous Kevin stands his ground as his frantic mother attempts to race home before Christmas Day.
## 13                                                                                                                                                                                                                                                                                                                A miserable conman and his partner pose as Santa and his Little Helper to rob department stores on Christmas Eve. But they run into problems when the conman befriends a troubled kid, and the security boss discovers the plot.
## 14                                                                                                                                                                                                                                                                                            A petty thief posing as an actor is brought to Los Angeles for an unlikely audition and finds himself in the middle of a murder investigation along with his high school dream girl and a detective who's been training him for his upcoming role...
## 15                                                                                                                                                                                                                                                                                                                                              When a doubting young boy takes an extraordinary train ride to the North Pole, he embarks on a journey of self-discovery that shows him that the wonder of life never fades for those who believe.
## 16                                                                                                                                                                                                                     Instead of flying to Florida with his folks, Kevin ends up alone in New York, where he gets a hotel room with his dad's credit card—despite problems from a clerk and meddling bellboy. But when Kevin runs into his old nemeses, the Wet Bandits, he's determined to foil their plans to rob a toy store on Christmas eve.
## 17                                                                                                                                                   Miser Ebenezer Scrooge is awakened on Christmas Eve by spirits who reveal to him his own miserable existence, what opportunities he wasted in his youth, his current cruelties, and the dire fate that awaits him if he does not change his ways. Scrooge is faced with his own story of growing bitterness and meanness, and must decide what his own future will hold: death or redemption.
## 18                                                                                                                                                                                                             A holiday favourite for generations...  George Bailey has spent his entire life giving to the people of Bedford Falls.  All that prevents rich skinflint Mr. Potter from taking over the entire town is George's modest building and loan company.  But on Christmas Eve the business's $8,000 is lost and George's troubles begin.
## 19                                                                          In this modern take on Charles Dickens' "A Christmas Carol," Frank Cross (Bill Murray) is a wildly successful television executive whose cold ambition and curmudgeonly nature has driven away the love of his life, Claire Phillips (Karen Allen). But after firing a staff member, Eliot Loudermilk (Bobcat Goldthwait), on Christmas Eve, Frank is visited by a series of ghosts who give him a chance to re-evaluate his actions and right the wrongs of his past.
## 20                                                                                                                                                                                               Scott Calvin is an ordinary man, who accidentally causes Santa Claus to fall from his roof on Christmas Eve and is knocked unconscious. When he and his young son finish Santa's trip and deliveries, they go to the North Pole, where Scott learns he must become the new Santa and convince those he loves that he is indeed, Father Christmas.
## 21                                                                                                                                                                                                          Scrooge is a miserly old businessman in 1840s London. One Christmas Eve he is visited by the ghost of Marley, his dead business partner. Marley foretells that Scrooge will be visited by three spirits, each of whom will attempt to show Scrooge the error of his ways. Will Scrooge reform his ways in time to celebrate Christmas?
## 22                                                                                                                                                                                                                                                                                                                                                                                                         A horror film that depicts St. Nicholas as a murderous bishop who kidnaps and murders children when there is a full moon on December 5.
## 23                                                                                                                                                                                                                                                                                                                                                                                                    A sorority house is terrorized by a stranger who makes frightening phone calls and then murders the sorority sisters during Christmas break.
## 24                                                                                                                                                                                                                                                                                                                                                                          Follows seemingly unrelated people as their lives begin to intertwine while they fall in – and out – of love. Affections languish and develop as Christmas draws near.
## 25                                                                                                                                                                                                                            It's Christmas time and the Griswolds are preparing for a family seasonal celebration, but things never run smoothly for Clark, his wife Ellen and their two kids. Clark's continual bad luck is worsened by his obnoxious family guests, but he manages to keep going knowing that his Christmas bonus is due soon.
## 26                                                                                                                                                                                                                                                                                                                                                                                                                                          A horror comedy based on the ancient legend about a pagan creature who punishes children on Christmas.
##    adult                    backdrop_path media_type
## 1  FALSE /oJ6LNvBLNWW4W7f9ffGN7S6odde.jpg      movie
## 2  FALSE /lHdG4SQa1GT2h52svEOyDEQ6bMD.jpg      movie
## 3  FALSE /bAXoW8wk7cBgPqK9pzPddvlAl2b.jpg      movie
## 4  FALSE /t4WQ36MAZf1sgiPKocTa0KBGBKI.jpg      movie
## 5  FALSE /qyNEqB6gl9V2GkiT88Pu36mqHnR.jpg      movie
## 6  FALSE /16lk65YfrDFIr6evkWRjSeOOSws.jpg      movie
## 7  FALSE /lmjjlXwNeRqmKBuA0a6jqOyTnZG.jpg      movie
## 8  FALSE /guTNnSWS3CaH71jasY8W1FMptjG.jpg      movie
## 9  FALSE /phFpSgDbgp4j6Eg0fhmueC3uyVS.jpg      movie
## 10 FALSE /txg7L67hkFQb7Sa0FzyuJwtxYaO.jpg      movie
## 11 FALSE /oeQoePt9S4V3KHhZK1CWZE2yJrr.jpg      movie
## 12 FALSE /rRNsAIYiJdQHULseGsV9fQSOTDc.jpg      movie
## 13 FALSE /efXWE0pzLchBKIXAKL3XmEQH1eo.jpg      movie
## 14 FALSE /9KC8SBwUU3DzsXE6QQF6gk1Jy2d.jpg      movie
## 15 FALSE /vQuIi5iOCN3V6yg7nbP5HUiVnpK.jpg      movie
## 16 FALSE /1uHTuwx5h9T3XzsXijMMKybDFvZ.jpg      movie
## 17 FALSE /Awx3ld6kRqq0iMKPPCUTt1RidCn.jpg      movie
## 18 FALSE /whxy3UQrbHswzXH6jfH7IGAIjLa.jpg      movie
## 19 FALSE /lktcffPqtBIL7OTuAN4pXgjXzOJ.jpg      movie
## 20 FALSE /rcQZmnhcb6P4mkgJAHnCYp3c1gp.jpg      movie
## 21 FALSE /fef2sQ0iuj1ZuhYZZTZIuVb2hZG.jpg      movie
## 22 FALSE /aTI2PMZbY09kKLn78plK3gCX3Vx.jpg      movie
## 23 FALSE /vkOQQ0zPTWzosHrcYcEhRJ17Uer.jpg      movie
## 24 FALSE /6xrA9tMvpb3cnktNH7voJ62S41N.jpg      movie
## 25 FALSE /8TNf3mbv4Wv9t6KMkxLUkCrB6SJ.jpg      movie
## 26 FALSE /eSJtPyyz90IaXW5JFEJo9WSfPtk.jpg      movie
##                                    title     id original_language
## 1         Rare Exports: A Christmas Tale  48395                fi
## 2                       Tokyo Godfathers  13398                ja
## 3                      A Christmas Story    850                en
## 4                       Arthur Christmas  51052                en
## 5                               Die Hard    562                en
## 6         The Nightmare Before Christmas   9479                en
## 7                                    Elf  10719                en
## 8                          Lethal Weapon    941                en
## 9                         Trading Places   1621                en
## 10                              Gremlins    927                en
## 11                      A Christmas Tale   8892                fr
## 12                            Home Alone    771                en
## 13                             Bad Santa  10147                en
## 14                   Kiss Kiss Bang Bang   5236                en
## 15                     The Polar Express   5255                en
## 16        Home Alone 2: Lost in New York    772                en
## 17                     A Christmas Carol  17979                en
## 18                 It's a Wonderful Life   1585                en
## 19                              Scrooged   9647                en
## 20                      The Santa Clause  11395                en
## 21                     A Christmas Carol  16716                en
## 22                                 Saint  45756                nl
## 23                       Black Christmas  16938                en
## 24                         Love Actually    508                en
## 25 National Lampoon's Christmas Vacation   5825                en
## 26                               Krampus 287903                en
## 
## $item_count
## [1] 26
## 
## $iso_639_1
## [1] "en"
## 
## $name
## [1] "Best Christmas Movies of All Time"
## 
## $poster_path
## [1] "/8clzN9mg7ZgPLtrwjAimon7pRSH.jpg"

This example uses a more serious keyword.

search_keyword(key_get("TMDB_API"), query = "racism")
## $page
## [1] 1
## 
## $results
##                name     id
## 1            racism  12425
## 2       anti-racism 257456
## 3   systemic racism 267085
## 4        gay racism 268247
## 5 systematic racism 268866
## 
## $total_pages
## [1] 1
## 
## $total_results
## [1] 5
one_page <- function(x) discover_movie(key_get("TMDB_API"), with_keywords = 12425, page = x)
pages <- 1:one_page(1)$total_pages
racism <- map_dfr(pages, function(x) one_page(x)$results)

glimpse(racism)
## Rows: 467
## Columns: 14
## $ vote_average      <dbl> 5.8, 6.8, 8.1, 8.1, 7.4, 7.6, 8.1, 6.9, 8.0, 7.8, 8…
## $ popularity        <dbl> 44.312, 38.379, 37.681, 35.800, 33.774, 30.826, 28.…
## $ overview          <chr> "The defiant leader Moses rises up against the Egyp…
## $ release_date      <chr> "2014-12-03", "1996-01-12", "1993-02-05", "2012-12-…
## $ title             <chr> "Exodus: Gods and Kings", "Don't Be a Menace to Sou…
## $ adult             <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA…
## $ backdrop_path     <chr> "/hwowjWNnBc7PKZNDHQyLfvywzVY.jpg", "/3Q8RLOraAukMb…
## $ genre_ids         <list> [<12, 18, 28>, 35, <28, 80, 18, 53>, <18, 37>, <18…
## $ vote_count        <int> 3496, 645, 616, 19481, 516, 12022, 7045, 110, 6306,…
## $ original_language <chr> "en", "en", "en", "en", "en", "en", "en", "en", "en…
## $ original_title    <chr> "Exodus: Gods and Kings", "Don't Be a Menace to Sou…
## $ poster_path       <chr> "/uaDj37JtvLan9tihxZ18e6qL33b.jpg", "/HZQBF7JDd2e9p…
## $ id                <int> 147441, 10607, 9702, 68718, 502425, 419430, 600, 33…
## $ video             <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FA…